home *** CD-ROM | disk | FTP | other *** search
- Path: news.uh.edu!sukku
- From: sukku@menudo.uh.edu (sukumar)
- Newsgroups: comp.lang.c
- Subject: GoTo equivalent in C ??
- Date: 12 Jan 1996 18:06:46 GMT
- Organization: University of Houston
- Message-ID: <4d67vm$e5h@masala.cc.uh.edu>
- NNTP-Posting-Host: menudo.uh.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Hi,
- I have always thought about this. How do you get the effect of goto
- in C without using "goto"?? For ex, if I have to check for an error in my
- function for every computation I do, and then do some cleaning up, how do
- I do it. Here is an example:
-
- f()
- {
-
- char *s = (char *) malloc(10 * sizeof(char));
- int i;
-
- i = scanf("%s", s);
-
- if(i != 1) /* I wish I could do a goto to the last two lines of the function*/
- {
- free(s);
- return;
- }
-
- i = atoi(s);
- if(i==0)
- {
- free(s);
- return;
-
- }
-
-
-
- ...
- ..
-
- free(s);
- return;
-
- }
-
-
- I don't want to use goto. what alternatievs do I have.
- Any ideas are greatly appreciated.
-
- -Srini.
-